﻿using System;
using System.Numerics;

namespace calendar_of_Jan
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //输入日历表第一天；
            string thefirstday = "2022-1-1";
            DateTime Thefirstday = Convert.ToDateTime(thefirstday);
            DateTime theday = Thefirstday;
            //每个月的天数；
            int[] monthday = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
            //初始化坐标和月
            int x = 0; int y = 0; int month = 1;
            //循环日历表主体；
            //共四行，一行三个月；
            for (int i = 0; i < 4; i++)
            {
                //一行中的月；
                for (int j = 0; j < 3; j++)
                {
                    x = 36 * j; y = 9 * i;
                    x++;
                    Console.SetCursorPosition(x, y);
                    Console.WriteLine(month + "月");
                    y++;
                    Console.SetCursorPosition(x, y);
                    Console.WriteLine("日  一  二  三  四  五  六");
                    y++;
                    Console.SetCursorPosition(x, y);
                    //确定一个月第一天的位置
                    int firstweekday = (int)theday.DayOfWeek;
                    Console.SetCursorPosition(x + 4 * (firstweekday), y);
                    x = x + 4 * (firstweekday);
                    //循环该月内的所有天
                    for (int k = 0; k < monthday[3 * i + j]; k++)
                    {
                        //日期
                        int day = (int)theday.Day;
                        //星期
                        int weekday = (int)theday.DayOfWeek;
                        //个位数前输入一个空格，对齐；
                        if (day < 10)
                        {
                            Console.Write(" " + day);
                            x += 4;
                        }
                        else
                        {
                            Console.Write(day);
                            x += 4;
                        }
                        //遇到星期六换行，并使光标回到该月x轴的首位；
                        if (weekday == 6)
                        {
                            //换行
                            y++;
                            //回光标
                            x = x - 28;
                        }
                        theday = theday.AddDays(1);
                        Console.SetCursorPosition(x, y);
                    }
                    month++;

                }
            }
        }
    }
}